import sys
import codecs

def parse_key(key):
    key1 = key.split(",")
    key2 = key1[0].split(" ")
    key3 = key2[1].split('"')
    return key3[1], key1[1]

def parse_m3u8(file_name):
    print(file_name)
    lines = []
    with open(file_name, "r+") as file:
        lines = file.readlines()
    index = 1
    cgroup = ""
    channel_map = {}
    while index < len(lines):
        key = lines[index].strip()
        value = lines[index+1].strip()
        group, channel = parse_key(key)
        index = index + 2
        if cgroup != group:
            if cgroup != "":
                print("")
            cgroup = group
            print(cgroup + ",#genre#")
        print(channel+","+value)



if __name__ == '__main__':
    if len(sys.argv) < 2:
        print("error param")
        exit(-1)
    parse_m3u8(sys.argv[1])
